import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description: X质数
 * User: DELL
 * Date: 2024-05-08
 * Time: 14:40
 */
public class Main1 {
    static boolean[] flag = new boolean[1000001];

    /**
     * 本题先直接筛选出 1000000 中的所有质数
     * 之后直接暴力判断即可
     *
     * @param args
     */

    public static void main(String[] args) {
        getAllPrime();
        int res = 0;
        for (int i = 1; i <= 1000000; i++) {
            int n = getLength(i);
            for (int j = 1; j < (1 << n); j++) {
                int temp = 0;
                int mul = 1;
                int mul2 = 1;
                for (int k = 0; k < n; k++) {
                    if ((j & (1 << k)) != 0) {
                        temp += ((i / mul2) % 10) * mul;
                        mul *= 10;
                    }
                    mul2 *= 10;
                }
                if (flag[temp]) {
                    res++;
                    break;
                }
            }
        }
        System.out.println(res);
    }

    /**
     * 获取一个数的位数
     *
     * @param n
     * @return
     */
    private static int getLength(int n) {
        int count = 0;
        while (n != 0) {
            n /= 10;
            count++;
        }
        return count;
    }

    /**
     * 利用欧拉晒筛选素数
     */
    private static void getAllPrime() {
        Arrays.fill(flag, true);
        flag[0] = false;
        flag[1] = false;
        for (int i = 2; i < 1000001; i++) {
            for (int j = 2; i * j < 1000001; j++) {
                flag[i * j] = false;
            }
        }
    }
}
